#!/bin/bash

if [ $# -lt 2 ]; then
   echo "There must be at least 2 command line arguments specified: $0 startIdx stopIdx [template]" 1>&2
   exit 1
fi

startIdx=$1
stopIdx=$2
template="stud%02d"
[ $# -ge 3 ] && template=$3

if [ $stopIdx -lt $startIdx ]; then
   echo "The 'startIdx' must be less or equal than 'stopIdx'" 1>&2
   exit 1
fi

for ((i=$startIdx;i<=$stopIdx;i++)); do 
	acc=$(printf $template $i); 
	res=$(ssh $acc@localhost "echo OK" 2> /dev/null); 
	if [ $res ]; then
		echo $acc: $res;
	else
		echo $acc: "-"
	fi 
done
